<?php

use think\migration\Migrator;

class CreateDeviceLogTable extends Migrator
{
    /**
     * 执行迁移
     */
    public function change()
    {
        // 创建设备日志表
        $table = $this->table('checkin_device_log', [
            'engine' => 'InnoDB',
            'collation' => 'utf8mb4_general_ci',
            'comment' => '设备操作日志表',
        ]);
        
        $table->addColumn('device_sn', 'string', ['limit' => 50, 'comment' => '设备序列号'])
              ->addColumn('member_id', 'integer', ['default' => 0, 'comment' => '会员ID'])
              ->addColumn('event_type', 'string', ['limit' => 50, 'comment' => '事件类型'])
              ->addColumn('event_data', 'text', ['null' => true, 'comment' => '事件数据(JSON)'])
              ->addColumn('error_code', 'integer', ['default' => 0, 'comment' => '错误代码'])
              ->addColumn('error_message', 'string', ['limit' => 500, 'default' => '', 'comment' => '错误信息'])
              ->addColumn('create_time', 'datetime', ['comment' => '创建时间'])
              ->addIndex(['device_sn'])
              ->addIndex(['member_id'])
              ->addIndex(['event_type'])
              ->addIndex(['create_time'])
              ->create();
    }
}
